package com.century.sjt.form;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

/**
 * Created by moon.zhong on 2015/3/2.
 */
public class FormFile {

    private String mName ;

    private String mValue ;

    private String mMime ;

    private File mFileName ;

    public FormFile(File mFileName) {
        this.mFileName = mFileName;
    }

    public String getName() {
//        return mName;
        return "uploadsound" ;
    }

    public String getFileName() {
        return "sound.amr";
    }

    public byte[] getValue() {
        int len = 0;
        ByteArrayOutputStream bos = new ByteArrayOutputStream() ;
        try {
            FileInputStream inputStream = new FileInputStream(mFileName);

            byte [] buffer = new byte[1024];
            while( (len = inputStream.read(buffer)) != -1){
                bos.write(buffer, 0, len);
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }catch (IOException e){
            e.printStackTrace();
        }
        return bos.toByteArray();
    }

    public String getMime() {
        return "multipart/form-data";
    }
}
